<?php

require_once dirname(__FILE__) . '/BasePost.php';

class UserPost extends BasePost
{
    public function addPost($title, $content, $type, $uid, $gid = 0,  $category_id = 0, $config = null) 
    {
        $ret = array('err' => ErrorDef::OK);
        try {
            // 参数校验
            if (empty($content) || !PostTypeDef::isSupport($type) || empty($uid))
            {
                throw new Exception('the value of content, type and uid can not be null and the type must be supported', ErrorDef::COMMON_ERROR_PARAM);
            }
            
            $content = Preprocessor::parseContent($type, $content);
            $post = PostData::addPost($title, $content, $type, $uid, 0, 0, $config);
            $ret['data'] = $post;
        }catch (Exception $e)
        {
            $err_code = $e->getCode();
            if (empty($err_code)) {
                $ret['err'] = ErrorDef::COMMON_ERROR_SYS;
            } else {
                $ret['err'] = $err_code;
            }
        }
        return $ret;
    }
}